package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseHistoricMilestoneInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricMilestoneInstanceQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricMilestoneInstanceResponse;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.HistoryMilestoneApi")
public class HistoryMilestoneApi {
    private ApiClient apiClient;

    public HistoryMilestoneApi() {
        this(new ApiClient());
    }

    @Autowired
    public HistoryMilestoneApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Get a historic milestone instance by id
     *
     * <p><b>200</b> - Indicates that the historic milestone instances could be found.
     * <p><b>404</b> - Indicates that the historic milestone instances could not be found.
     * @param milestoneInstanceId The milestoneInstanceId parameter
     * @return HistoricMilestoneInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public HistoricMilestoneInstanceResponse getHistoricMilestoneInstanceById(String milestoneInstanceId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'milestoneInstanceId' is set
        if (milestoneInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'milestoneInstanceId' when calling getHistoricMilestoneInstanceById");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("milestoneInstanceId", milestoneInstanceId);
        String path = UriComponentsBuilder.fromPath("/cmmn-history/historic-milestone-instances/{milestoneInstanceId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<HistoricMilestoneInstanceResponse> returnType = new ParameterizedTypeReference<HistoricMilestoneInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List of historic milestone instances
     *
     * <p><b>200</b> - Indicates that historic milestone instances could be queried.
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param milestoneId An id of the historic milestone instance.
     * @param milestoneName The name of the historic milestone instance
     * @param caseInstanceId The id of the case instance containing the milestone.
     * @param caseDefinitionId The id of the definition of the case where the milestone is defined.
     * @param reachedBefore Return only historic milestone instances that were reached before this date.
     * @param reachedAfter Return only historic milestone instances that were reached after this date.
     * @return DataResponseHistoricMilestoneInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricMilestoneInstanceResponse listHistoricMilestoneInstances(String milestoneId, String milestoneName, String caseInstanceId, String caseDefinitionId, String reachedBefore, String reachedAfter) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/cmmn-history/historic-milestone-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "milestoneId", milestoneId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "milestoneName", milestoneName));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "caseInstanceId", caseInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "caseDefinitionId", caseDefinitionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "reachedBefore", reachedBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "reachedAfter", reachedAfter));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricMilestoneInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricMilestoneInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query for historic milestone instances
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic milestone instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long.
     * <p><b>200</b> - Indicates request was successful and the milestone instances are returned
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseHistoricMilestoneInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricMilestoneInstanceResponse queryHistoricMilestoneInstance(HistoricMilestoneInstanceQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/cmmn-query/historic-milestone-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricMilestoneInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricMilestoneInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
